<?php
$current_month = date('n');
$last_month = null;
echo '<div class="timeline-container"><div>';
foreach ($rows as $r) {
	$message = Yii::t('message', $r['message_key'], json_decode($r['message_values'], true));
	$visit_time = Yii::app()->locale->dateFormatter->formatDateTime($r['ts_visit_time']);
	$icon_type = 'icon-map-marker btn';
	$action_type = '';
	if ($r['type'] == CustomerHelper::ACTION_EARN_POINT) {
		$icon_type = 'icon-star btn btn-orange';
		$action_type = 'Earned points';
	} elseif ($r['type'] == CustomerHelper::ACTION_REDEEM_REWARD) {
		$icon_type = 'icon-trophy btn btn-success';
		$action_type = 'Redeemed rewards';
	} elseif ($r['type'] == CustomerHelper::ACTION_REDEEM_OFFER) {
		$icon_type = 'icon-certificate btn btn-danger';
		$action_type = 'Redeemed offers';
	}
	
	//display timeline-label for month
	$visit_month = date('n', $r['ts_visit_time']);
	if ($visit_month == $current_month) {
		//display this month
		$label = Yii::t('app', 'This month');
	} else {
		$label = date('F', $r['ts_visit_time']);
	}
	
	if ($visit_month != $last_month) {
		$last_month = $visit_month;
		echo <<<HTML
</div>
<div class="timeline-label">
	<span class="label label-primary">
		<b>{$label}</b>
	</span>
</div>
<div class="timeline-items">
	<div class="timeline-item clearfix">
		<div class="timeline-info">
			<i class="timeline-indicator {$icon_type}"></i>
		</div>
		<div class="widget-box transparent">
			<div class="widget-header widget-header-small">
				<h5 class="smaller">{$action_type}</h5>
				<span class="widget-toolbar timeline-time">
					<i class="icon-time"></i> {$visit_time}
				</span>
			</div>
			<div class="widget-body">
				<div class="widget-main">
					{$message}
				</div>
			</div>
		</div>
	</div>
HTML;
	} else {
		echo <<<HTML
	<div class="timeline-item clearfix">
		<div class="timeline-info">
			<i class="timeline-indicator {$icon_type}"></i>
		</div>
		<div class="widget-box transparent">
			<div class="widget-header widget-header-small">
				<h5 class="smaller">{$action_type}</h5>
				<span class="widget-toolbar timeline-time">
					<i class="icon-time"></i> {$visit_time}
				</span>
			</div>
			<div class="widget-body">
				<div class="widget-main">
					{$message}
				</div>
			</div>
		</div>
	</div>
HTML;
	}
}
echo '</div></div>';